import ConfirmComponent from './confirm'

var $vm
let instance

function Toast (options){
	options = options || {}
	if(typeof options === 'string'){
		options = {
			name:options
		}
	}

	instance = new ConfirmComponent({
		el:document.createElement('div')
	})
	document.body.appendChild(instance.vm.$el)

	instance.vm = instance.$mount()
}

const install = vue => {
	const Confirm = vue.extend(ConfirmComponent)
	
    if (!$vm) {
		$vm = new Confirm({
			el: document.createElement('div')
		})
		document.body.appendChild($vm.$el)
	}

	var confirm = {
		show ( options ){
			$vm.text = options
			$vm.show = true
		}
	}

	if (!vue.$vux) {
		vue.$vux = {
            confirm
		}
	} else {
		vue.$vux.confirm = confirm
	}

	vue.mixin({
		created: function(){
			this.$vux = vue.$vux
		}
	})
}

export default install
